home *** CD-ROM | disk | FTP | other *** search
/ No Fragments Archive 12: Textmags & Docs / nf_archive_12.iso / MAGS / SOURCES / ATARI_SRC.ZIP / atari source / HDX_BACK / HDX504A / PART.C < prev    next >
Encoding:
C/C++ Source or Header  |  2001-02-09  |  8.1 KB  |  412 lines

  1. /* part.c */
  2.  
  3.  
  4. /*
  5.  * 24-Nov-88    jye.     change and add codes so that can be used for MS-DOS
  6.  */
  7. #include "obdefs.h"
  8. #include "gemdefs.h"
  9. #include "osbind.h"
  10. #include "mydefs.h"
  11. #include "part.h"
  12. #include "bsl.h"
  13. #include "hdx.h"
  14. #include "addr.h"
  15.  
  16.  
  17. extern char sbuf[];
  18. extern int npart;
  19. extern int uplim;
  20. extern long bslsiz;
  21. extern long gbslsiz();
  22. extern int noinfo;        /* 1: no information inside the wincap */
  23.  
  24. /*
  25.  * Complain about partition error.
  26.  *
  27.  */
  28. parterr(devno)
  29. int devno;
  30. {
  31.     char *pdev="X";
  32.     int tmp;
  33.     
  34.     tmp = devno;
  35.     if (devno > 15) 
  36.         tmp = devno - 16;
  37.     else if (devno > 7)
  38.         tmp = devno - 8;
  39.     *pdev = tmp + '0';
  40.     (cantpart[PTNDEV].ob_spec)->te_ptext = pdev;
  41.     cantpart[PTNERROK].ob_state = NORMAL;
  42.     execform(cantpart);
  43.     return ERROR;
  44. }
  45.  
  46.  
  47. /*
  48.  * Fill in partition entry with default information
  49.  * and configuration values from the current "pr" wincap entry.
  50.  *
  51.  */
  52. fillpart(n, part)
  53. int n;
  54. PART *part;
  55. {
  56.     long num;
  57.     char *partid;
  58.     char *idstr = "XX";
  59.     char *wgetstr();
  60.  
  61.     idstr[1] = n + '0';
  62.  
  63.     /* see if `pX' is mentioned */
  64.     *idstr = 'p';
  65.     if (wgetnum(idstr, &num) == OK)
  66.     {
  67.     /* do the ST partition assignment */
  68.         npart++;
  69.         part->p_siz = (LONG)(num / 512);
  70.            part->p_flg = P_EXISTS;
  71.         if (part->p_siz < MB16)    {
  72.             part->p_id[0] = 'G';
  73.             part->p_id[1] = 'E';
  74.             part->p_id[2] = 'M';
  75.         } else {
  76.             part->p_id[0] = 'B';
  77.             part->p_id[1] = 'G';
  78.             part->p_id[2] = 'M';
  79.         }
  80.     }
  81. }
  82.  
  83.  
  84. /* set the partition informations to the partition structures */
  85.  
  86. setpart(part, pnam, hsize)
  87. PART *part;
  88. char *pnam;
  89. long hsize;
  90. {
  91.     long onepart, remain;
  92.     int i;
  93.  
  94.     npart = 4;
  95.     if ((!noinfo) && (*pnam))     {
  96.         /* there is a partition scheme inside the wincap */
  97.         msetpart(part, pnam, hsize);
  98.         return OK;
  99.     }
  100.     onepart = hsize/4;
  101.     remain = (hsize - onepart * 4) / 4;
  102.     for ( i = 0; i < 4; i++, part++)    {
  103.         if (i == 4)    {
  104.             part->p_siz = hsize - (onepart + remain) * 3;
  105.         } else {
  106.             part->p_siz = onepart+remain;
  107.         }
  108.            part->p_flg = P_EXISTS;
  109.         if (part->p_siz < MB16)    {
  110.                part->p_id[0] = 'G';
  111.                part->p_id[1] = 'E';
  112.                part->p_id[2] = 'M';
  113.         } else {
  114.                part->p_id[0] = 'B';
  115.                part->p_id[1] = 'G';
  116.                part->p_id[2] = 'M';
  117.         }
  118.     }
  119. }
  120.  
  121. /* set the partition informations from the 'pname'.     */
  122. /* For example, pname = 12-12-14-14                        */        
  123.  
  124. msetpart(part, pname, hsize)
  125. PART *part;
  126. char *pname;
  127. long hsize;
  128. {
  129.     long part1, part2, part3, part4, remain;
  130.     int i, np;
  131.  
  132.     npart = 4;
  133.     np = 4;
  134.     convs2i(pname, &part1, 1);        /* 1: get first ASCII */
  135.     if (convs2i(pname, &part2, 2) == 1)        {        /* 2: get second ASCII */
  136.         /* only one partition */
  137.         part2 = 0;
  138.         part3 = 0;
  139.         part4 = 0;
  140.         np = 1;
  141.     } else if (convs2i(pname, &part3, 3) == 2)    {    /* 3: get third ASCII */
  142.         /* only two partitions */
  143.         part3 = 0;
  144.         part4 = 0;
  145.         np = 2;
  146.     } else if (convs2i(pname, &part4, 4) == 3)    {    /* 4: get fourth ASCII */
  147.         /* only three partitions */
  148.         part4 = 0;
  149.         np = 3;
  150.     }
  151.     remain = (hsize - (part1 + part2 + part3 + part4)) / np;
  152.     if (np == 1)    {
  153.         part1 = hsize;
  154.     } else if (np == 2)    {
  155.         part1 += remain;
  156.         part2 = hsize - part1;
  157.     } else if (np == 3)    {
  158.         part1 += remain;
  159.         part2 += remain;
  160.         part3 = hsize - part1 - part2;
  161.     } else {
  162.         part1 += remain;
  163.         part2 += remain;
  164.         part3 += remain;
  165.         part4 = hsize - part1 - part2 - part3;
  166.     }
  167.     for ( i = 0; i < 4; i++, part++)    {
  168.         switch(i)    {
  169.             case 0:    part->p_siz = part1;
  170.                     break;
  171.             case 1:    part->p_siz = part2;
  172.                     break;
  173.             case 2:    part->p_siz = part3;
  174.                     break;
  175.             case 3:    part->p_siz = part4;
  176.                     break;
  177.         }
  178.         if (!part->p_siz) continue;
  179.            part->p_flg = P_EXISTS;
  180.         if (part->p_siz < MB16)    {
  181.                part->p_id[0] = 'G';
  182.                part->p_id[1] = 'E';
  183.                part->p_id[2] = 'M';
  184.         } else {
  185.                part->p_id[0] = 'B';
  186.                part->p_id[1] = 'G';
  187.                part->p_id[2] = 'M';
  188.         }
  189.     }
  190. }
  191.  
  192.  
  193. /* conver the string 12-12-14-14 to a integer */
  194.  
  195. convs2i(pname, num, flag)
  196.  
  197. char *pname;
  198. long *num;
  199. int flag;        /* 1: conver the first one. 3: conver the third one */
  200.  
  201. {
  202.     char tem[10], *ptr;
  203.     int i;
  204.     UWORD n=0;
  205.  
  206.     ptr = pname;
  207.     for (i = 0; i < 10; i++)
  208.         tem[i] = "\0";
  209.  
  210.     if (flag == 2)    {    /* conver the second one of pname */
  211.         while ((*ptr != '-') && (*ptr))      ptr++;
  212.         if (!*ptr)  return 1;    /* only one partition */
  213.         ptr++;
  214.     } else if (flag == 3)    {    /* conver the third one of 12-12-14-14 */
  215.         while (*ptr != '-')     ptr++;
  216.         ptr++;
  217.         while ((*ptr != '-') && (*ptr))      ptr++;
  218.         if (!*ptr) return 2;        /* only two partitions */
  219.         ptr++;
  220.     } else if (flag == 4)    {
  221.         while (*ptr != '-')     ptr++;
  222.         ptr++;
  223.         while (*ptr != '-')     ptr++;
  224.         ptr++;
  225.         while ((*ptr != '-') && (*ptr))      ptr++;
  226.         if (!*ptr) return 3;        /* only three partitions */
  227.         ptr++;
  228.     }
  229.     /* copy the string into the buf */
  230.     for (i = 0; (*ptr != '-')&&(*ptr); )    {
  231.         tem[i++] = *ptr++;
  232.     }
  233.  
  234.     /* conver the string to integer */
  235.     for (i = 0; tem[i] >= '0' && tem[i] <= '9'; ++i)
  236.         n = 10 * n + (UWORD)(tem[i] - '0');
  237.  
  238.     *num = (long)n * 2048;
  239.     if (!n) return(flag - 1);
  240.     return OK;
  241. }
  242.  
  243.  
  244.  
  245. /* set the menu partition scheme */
  246.  
  247. setschm(dsize, partnames)
  248.  
  249. long dsize;
  250. char *partnames;
  251.  
  252. {
  253.     int part12;
  254.     int part34;
  255.     int tmp1, tmp2;
  256.     int i, siz, index=2;
  257.  
  258.     siz = dsize/2048;
  259.     for (i = 0; i < NAMSIZ; i++)    {
  260.         partnames[i] = '\0';
  261.     }
  262.     tmp1 = dsize/(2048*4);
  263.     tmp2 = (siz - tmp1*4)/4;
  264.     itoas(partnames, tmp1+tmp2, 0);
  265.     itoas(partnames, tmp1+tmp2, 1);
  266.  
  267.     if (siz > 47)    /* when index > 2, siz should > 47 */
  268.         index = siz/16;
  269.     part34 = dsize/(2048*4) - index;
  270.     part12 = part34 + 2*index;
  271.     for (i = 0; i < 4; i++)    {
  272.         if (!part34)        /* add the remainder into part12 */
  273.             part12 += (siz - 2 * part12) / 2;
  274.         itoas(partnames, part12, 0);
  275.         itoas(partnames, part34, 1);
  276.         if (part34 == 1)    {        
  277.             part12++;         /* add the remainder into part12 */
  278.             part34 = 0;
  279.         } else {
  280.             part34 -= index;
  281.             part12 += index;
  282.         }
  283.         if (part34 < 0) break;
  284.     }
  285. }
  286.  
  287.  
  288. /* convert the integer into ASCII and store it into a buffer like    */
  289. /* 12-12 if the integer is 12                                         */
  290.  
  291. itoas(buf, num, flag)
  292. char *buf;
  293. int num;
  294. int flag;         /* 1: put second part of scheme. Now buf = 12-12\0 */
  295.  
  296. {
  297.     int i=0, j;
  298.     char tem[10];
  299.  
  300.     if (*buf)    { /* 12-12-14-14\010-10\0 inside the buf */
  301.     skp:
  302.         while (*buf)    buf++;
  303.         if ((!flag) || (*(buf+1)))     buf++;        /* skip between string */
  304.         if (*buf)     {
  305.             goto skp;
  306.         }
  307.         if (flag)    {    /* put second part of scheme */ 
  308.             *buf++ = '-';
  309.         }
  310.     } 
  311.     /* conver the integer to ASCII */
  312.     do    {    /* generate digits in reverse order */
  313.         tem[i++] = num % 10 + '0';        /* get next digits */
  314.     } while ((num /= 10) > 0);            /* delete it */
  315.  
  316.     j = i;
  317.     for (; i > 0; )    {    /* reverse string 'buf' in place */
  318.         *buf++ = tem[--i];
  319.     }
  320.     *buf++ = '-';
  321.     for (; j > 0; )    {    /* reverse string 'buf' in place */
  322.         *buf++ = tem[--j];
  323.     }
  324.     *buf++ = '\0';
  325. }
  326.  
  327.  
  328. /*
  329.  * Force checksum of sector image to a value
  330.  */
  331. forcesum(image, sum)
  332. UWORD *image;
  333. UWORD sum;
  334. {
  335.     register int i;
  336.     register UWORD w;
  337.  
  338.     w = 0;
  339.     /* up limit is half of buffer size - 2 */
  340.     for (i = 0; i < ((UWORD)BPS/2 - 1); ++i)
  341.     w += *image++;
  342.     *image++ = sum - w;
  343. }
  344.  
  345.  
  346. /*
  347.  * Put word in memory in 8086 byte-reversed format.
  348.  *
  349.  */
  350. iw(wp, w)
  351. UWORD *wp;
  352. UWORD w;
  353. {
  354.     char *p;
  355.  
  356.     p = (char *)wp;
  357.     p[0] = (w & 0xff);
  358.     p[1] = ((w >> 8) & 0xff);
  359. }
  360.  
  361. /*
  362.  * Put long word in memory in 8086 word-reversed format.
  363.  *
  364.  */
  365. ilong(lp, l)
  366. long *lp;
  367. long l;
  368. {
  369.     UWORD *p;
  370.  
  371.     p = (UWORD *)lp;
  372.     iw(&p[0],(UWORD)(l & 0xffff));
  373.     iw(&p[1],(UWORD)((l >> 16) & 0xffff));
  374. }
  375.  
  376. /*
  377.  * Get long word in memory, from 8086 word-reversed format.
  378.  *
  379.  */
  380. glong(al, lp)   /* al is a swaped return long word,*/
  381.                 /* lp is a to be swaped long word */
  382. long *al;
  383. long *lp;
  384.  
  385. {
  386.    char *p, *q;
  387.  
  388.     p = (char *)al;
  389.     q = (char *)lp;
  390.     p[0] = q[3];
  391.     p[1] = q[2];
  392.     p[2] = q[1];
  393.     p[3] = q[0];
  394. }
  395.  
  396. /*
  397.  * Get word in memory, from 8086 byte-reversed format.
  398.  *
  399.  */
  400. UWORD gw(wp, aw)
  401. UWORD *wp;
  402. UWORD *aw;
  403. {
  404.     char *p, *q;
  405.  
  406.     p = (char *)wp;
  407.     q = (char *)aw;
  408.     q[0] = p[1];
  409.     q[1] = p[0];
  410.     return *aw;
  411. }
  412.